package com.weimob.mcloud.wechatwork.customer.externalDependencyProxy.adapter;

import com.alibaba.dubbo.config.annotation.Reference;
import com.google.common.collect.Lists;
import com.weimob.mcloud.wechatwork.core.adapter.pojo.dto.ec.request.BatchMigrationStatusRequest;
import com.weimob.mcloud.wechatwork.core.adapter.pojo.dto.ec.response.BatchMigrationStatusVo;
import com.weimob.mcloud.wechatwork.core.adapter.service.EcAdapterService;
import com.weimob.soa.common.utils.SoaUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author yuanhao
 * @date 2023/4/24 14:40
 */
@Slf4j
@Component
public class EcAdapterServiceProxy {

    @Reference
    private EcAdapterService ecAdapterService;

    /**
     * 获取迁移状态
     *
     * @param bosId bosId
     * @return BatchMigrationStatusVo
     */
    public BatchMigrationStatusVo getMigrationStatusVO(Long bosId) {
        BatchMigrationStatusRequest batchMigrationStatusRequest = new BatchMigrationStatusRequest();
        batchMigrationStatusRequest.setBosId(Lists.newArrayList(bosId));
        List<BatchMigrationStatusVo> batchMigrationStatus = SoaUtil.unpack(ecAdapterService.batchMigrationStatus(batchMigrationStatusRequest));
        if (CollectionUtils.isEmpty(batchMigrationStatus)) {
            return null;
        }
        return batchMigrationStatus.get(0);
    }
}
